DC motors (or just “motors”) can spin when a current is applied. By reversing the current the motor spins in the opposite direction. By changing the voltage the motor spins faster or slower. The Kitronik robotics board handles the speed and direction control for us.
Connect the two wires of the motor to the MOTOR1 connector on the Kitronik board. Connect a battery to the + and - connectors (+ to red) on the Kitronik board.
You need to add the Kitronik extension. Copy the PicoRobotics.py file from the lib directory on github to the lib directory on the pico:
Write this code and download to the Pico.
See code on github# Test motor with kitronik robotics board
import PicoRobotics
import time
# Create robotics object
robot = PicoRobotics.KitronikPicoRobotics()
print("Forward")
for speed in range(0,100):
robot.motorOn(1, "f", speed)
time.sleep(0.1)
print("Reverse")
for speed in range(0,100):
robot.motorOn(1, "r", speed)
time.sleep(0.1)
print("Stop")
robot.motorOff(1)